import { Component } from "react";
import axios from 'axios'

class App extends Component {
    state = {
        items: [],
        isLoading: true
    }



    render() {
        if (this.state.isLoading) {
            return (<h3>正在加载中。。。</h3>)
        } else {
            return (
                this.state.items.map((value) => {
                    return (
                        <div key={value.id}>
                            <p>{value.name}</p>
                        </div>
                    )
                })
            )
        }
    }

    getData() {
        axios.interceptors.response.use((res) => {
            return res.data
        })
        axios.get('http://localhost:9999/data.json').then(
            (value) => {
                this.setState({
                    items: value.items,
                    isLoading: false
                })
            }
        )
    }

    componentDidMount() {
        this.getData()
    }
}
export default App